package com.liu.common.util;

import com.liu.common.entity.ExcelConstant;

import java.io.File;
import java.text.MessageFormat;
import java.util.Calendar;

public class FileUtils {
    /**
     * 获取文件按日期存放路径
     * */
    public static String getExcelExportPathByDate(){
        String year = String.valueOf(Calendar.getInstance(DateUtils.getTimeZone()).get(Calendar.YEAR));
        String month = String.valueOf(Calendar.getInstance(DateUtils.getTimeZone()).get(Calendar.MONTH)+1);
        String day = String.valueOf(Calendar.getInstance(DateUtils.getTimeZone()).get(Calendar.DAY_OF_MONTH));
        if(month.length() < 2){
            month = "0"+month;
        }
        if(day.length() <2){
            day = "0"+day;
        }
        return MessageFormat.format(ExcelConstant.EXCEL_EXPORT_DATE_PATH,year,month,day);
    }


    /**
     * 获取文件固定存放路径
     * */
    public static String getExcelExportPath(){
        return ExcelConstant.EXCEL_EXPORT_PATH;
    }


    /**
     * 创建目录
     * */
    public static void isNewFolder(String folder){
        File file = new File(folder);
        if(!file.exists()){
            file.mkdirs();
        }
    }

    public static String getFilePath(String fileName) {
        //获取存放目录路径
        String fileDirPath = FileUtils.getExcelExportPath();
        //创建目录
        FileUtils.isNewFolder(fileDirPath);
        return fileDirPath + "/" + System.currentTimeMillis() + fileName;
    }
}
